import java.util.concurrent.Semaphore;

/**
 * Created with IntelliJ IDEA.
 * User:xieChao
 * Date:2022/11/5 22:13
 */
public class Test2 {
    public static void main(String[] args) throws InterruptedException {
        //4就是表示可用资源有4个
        Semaphore semaphore = new Semaphore(4);
        //申请资源，P操作
        semaphore.acquire();
        System.out.println("申请成功！");
        semaphore.acquire();
        System.out.println("申请成功！");
        semaphore.acquire();
        System.out.println("申请成功！");
        semaphore.acquire();
        System.out.println("申请成功！");
        //释放资源，V操作
        semaphore.release();

    }
}
